package config

import "github.com/spf13/viper"

type Config struct {
	Port           int    `yaml:"port" mapstructure:"port"`
	InCluster      bool   `yaml:"in_cluster" mapstructure:"in_cluster"`
	KubeconfigFile string `yaml:"kubeconfig_file" mapstructure:"kubeconfig_file"`
}

// InitGlobalConfig 初始化全局配置，解析application.yaml文件
func InitGlobalConfig() (*Config, error) {
	v := viper.New()
	v.SetConfigFile("application.yaml")

	if err := v.ReadInConfig(); err != nil {
		return nil, err
	}
	cfg := &Config{}
	if err := v.Unmarshal(cfg); err != nil {
		return nil, err
	}
	return cfg, nil
}
